package com.zz.parkingsystem.exception;

import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ValidatedException {
    @ExceptionHandler(BindException.class)
    public Result validatedException(BindException bindException){
        return ResultGenerator.genFailResult(bindException.getFieldError().getDefaultMessage());
    }
}
